#ifndef _WRESULT_H
#define _WRESULT_H

#include <string>
#include <map>
using namespace std;

typedef long WRESULT;

#define WFAILED(hr) (((WRESULT)(hr)) > 0)
#define WSUCCEEDED(hr) (((WRESULT)(hr)) == 0)

const wstring W_OK = L"W_OK";
const wstring W_FAILURE = L"W_FAILURE";
const wstring W_CON = L"W_CON";
const wstring W_DIR = L"W_DIR";
const wstring W_PROC = L"W_PROC";
const wstring W_SHR = L"W_SHR";
const wstring W_REG = L"W_REG";

class WResult
{
public:
    WResult()
    {
    }

    WResult(wstring n, wstring des, long v)
    {
        name = n;
        description = des;
        value = v;
    }

    wstring name;
    wstring description;
    long value;
};

class WResultMap
{
private:
    WResultMap()
    {
        resMap[W_OK] = WResult(L"W_OK", L"Operation successful", 0);
        resMap[W_FAILURE] = WResult(L"W_FAILURE", L"Operation failure", -1);
        resMap[W_CON] = WResult(L"W_CON", L"Connection failure", 100);
        resMap[W_DIR] = WResult(L"W_DIR", L"FileDirectory operation failure", 200);
        resMap[W_PROC] = WResult(L"W_PROC", L"Proccess operation failure", 300);
        resMap[W_SHR] = WResult(L"W_SHR", L"Share operation failure", 400);
        resMap[W_REG] = WResult(L"W_REG", L"Reg operation failure", 500);
    }

public:
    static WResultMap* instance()
    {
        if (!pinstance)
        {
            pinstance = new WResultMap;
        }

        return pinstance;
    }

    WRESULT get(wstring key)
    {
        return resMap[key].value;
    }

    wstring getDescription(WRESULT wr)
    {
        map<wstring, WResult>::iterator it;
        for ( it=resMap.begin() ; it != resMap.end(); it++ )
        {
            if((*it).second.value == wr)
            {
                return (*it).second.description;
            }
        }
        return L"";
    }

private:
    static WResultMap* pinstance;
    std::map<wstring, WResult> resMap;    
};

WResultMap *WResultMap::pinstance = 0;

WRESULT getResult(wstring key)
{
    WResultMap *rmap = WResultMap::instance();
    return rmap->get(key);
}

wstring getDescription(WRESULT wr)
{
    WResultMap *rmap = WResultMap::instance();
    return rmap->getDescription(wr);
}

#endif